package com.h117121.fashionshop.core;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.h117121.fashionshop.core.tool.DataGenerator;

public class Main {
	private static final Log logger = LogFactory.getLog(Main.class);

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		logger.info("Started...");
		ApplicationContext appContext = new ClassPathXmlApplicationContext(
				"config/SpringConfig.xml");

		DataGenerator generator = (DataGenerator) appContext
				.getBean("dataGenerator");
		generator.generateData(1000, 1000, 1000, 10);
		// generator.generateInvoices(100, 20);

		// ProductDao productDao = (ProductDao)
		// appContext.getBean("productDao");
		// AccountDao accountDao = (AccountDao)
		// appContext.getBean("accountDao");
		// CommentDao commentDao = (CommentDao)
		// appContext.getBean("commentDao");
		// InvoiceDao invoiceDao = (InvoiceDao)
		// appContext.getBean("invoiceDao");
		//
		// AccountService accountService = (AccountService) appContext
		// .getBean("accountService");
		// String query = "";

		// System.out.println("####====== All products ======####");
		// List<Product> all = productDao.getAll();
		// for (Product product : all) {
		// System.out.println(product);
		// }

		// query = "xiÄ‘a";
		// System.out.println("====== Query by: " + query + " ======");
		// List<Product> rs1 = productDao.findByPrice(400000, 500000);
		// for (Product product : rs1) {
		// System.out.println(product);
		// }
		// System.out.println("=> " + rs1.size() + " results");

		// query = "ThÃ¡i Tuáº¥n";
		// System.out.println("====== Query by Producer name: " + query
		// + " ======");
		// List<Product> rs2 = productDao.findByProducerName(query);
		// for (Product product : rs2) {
		// System.out.println(product);
		// }

		// query = "Ã�o";
		// System.out
		// .println("====== Query by Product type: " + query + " ======");
		// List<Product> rs3 = productDao.findByProductType(query);
		// for (Product product : rs3) {
		// System.out.println(product);
		// }

		// System.out.println("====== Query by Product price ======");
		// List<Product> rs3 = productDao.findByProductType(query);
		// for (Product product : rs3) {
		// System.out.println(product);
		// }

		// DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
		// Date date = null;
		// try {
		// date = formatter.parse("01/01/2011");
		// } catch (Exception e) {
		// e.printStackTrace();
		// }
		// query = date.toString();
		// System.out.println("====== Query by DateAdded (exactly): " + query
		// + " ======");
		// List<Product> rs4 = productDao.findByDateAdded(date,
		// DateQueryType.EXACTLY);
		// for (Product product : rs4) {
		// System.out.println(product);
		// }
		// System.out.println("=> " + rs4.size() + " results");

		// System.out.println("====== Query by DateAdded (before): " + query
		// + " ======");
		// List<Product> rs5 = productDao.findByDateAdded(date,
		// DateQueryType.BEFORE);
		// for (Product product : rs5) {
		// System.out.println(product);
		// }
		//
		// System.out.println("====== Query by DateAdded (after): " + query
		// + " ======");
		// List<Product> rs6 = productDao.findByDateAdded(date,
		// DateQueryType.AFTER);
		// for (Product product : rs6) {
		// System.out.println(product);
		// }

		// System.out.println("####====== All accounts ======####");
		// List<Account> allAccounts = accountDao.getAll();
		// for (Account acc : allAccounts) {
		// System.out.println(acc);
		// }

		// System.out.println("####====== All comments ======####");
		// List<Comment> allComments = commentDao.getAll();
		// for (Comment comment : allComments) {
		// System.out.println(comment);
		// }

		// System.out.println("####====== Query comments by account (Account) ======####");
		// List<Comment> cm =
		// accountDao.findAllCommentsByUsername(allAccounts.get(0).getUserName());
		// for (Comment comment : cm) {
		// System.out.println(comment);
		// }

		// for (int i = 0; i < 10; i++) {
		// System.out
		// .println("####====== Query comments by account (Comment) ======####");
		// List<Comment> cm2 = commentDao
		// .findAllCommentsByUsername(allAccounts.get(i).getUserName());
		// for (Comment comment : cm2) {
		// System.out.println(comment);
		// }
		// }

		// System.out.println("####====== Query comments by content ======####");
		// List<Comment> allComments = commentDao.findByContent("!");
		// for (Comment comment : allComments) {
		// System.out.println(comment);
		// }
		// System.out.println("=> " + allComments.size() + " results");

		// System.out.println("####====== Query invoice by method ======####");
		// List<Invoice> invoiceRs = invoiceDao
		// .findByPaymentMethod(PaymentMethod.HOME);
		// for (Invoice invoice : invoiceRs) {
		// System.out.println(invoice);
		// }
		// System.out.println("=> " + invoiceRs.size() + " results");

		// System.out.println("####====== Query invoice by username ======####");
		// List<Invoice> invoiceRs2 = invoiceDao
		// .findByUsername("Admin");
		// for (Invoice invoice : invoiceRs2) {
		// System.out.println(invoice);
		// }
		// System.out.println("=> " + invoiceRs2.size() + " results");
		//
		// logger.info("Finished");

		// System.out.println("####====== Query invoice by product name ======####");
		// List<Invoice> invoiceRs3 = invoiceDao.findByProductName("quáº§n");
		// for (Invoice invoice : invoiceRs3) {
		// System.out.println(invoice);
		// }
		// System.out.println("=> " + invoiceRs3.size() + " results");

		logger.info("Finished");
	}
}